﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;

public partial class salesreport : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
         Session["current"] = "Sales Report";//current page
        if (Session["user"] != null)//check user
        {
            string user = Session["user"].ToString();
            if (user == "viewer")
            {
                Response.Redirect("index.aspx");
            }

        }
        else
        {
            Response.Redirect("index.aspx");
        }

        ASPxDateEdit1.Visible = false;
        ASPxDateEdit2.Visible = false;
        DropDownList1.Visible = false;
        Label2.Visible = false;
        Label5.Visible = false;
        Label6.Visible = false;


        if (IsPostBack == true)//check selected radio button
        {
            //Session["button"] = "0";
            if (Session["button"] !=null)
            {
                string button = Session["button"].ToString();

                if (button == "1")
                {
                    button1();
                    button1();
                }
                else
                    if (button == "2")
                    {
                        button2();
                        button2();
                    }
                   
                        button3();
                        button3();
                    
            }
           
          
        }
    }
    protected void ASPxButton1_Click(object sender, EventArgs e)
    {
        if (ASPxRadioButton1.Checked)
        {
            button1();
        }
        else if (ASPxRadioButton2.Checked)
        {
            button2();
        }
        else
        {
            button3();
        }
    }

    protected void ASPxRadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        if (ASPxRadioButton1.Checked)
        {
            ASPxDateEdit1.Visible = true;
            ASPxDateEdit2.Visible = true;
            Label5.Visible = true;
            Label6.Visible = true;

        }
    }

    protected void ASPxRadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        if (ASPxRadioButton2.Checked)
        {
            Label2.Visible = true;
            DropDownList1.Visible = true;
        }
    }

    #region radio button actions
    public Boolean button1()
    {
        ReportDocument reportdocument = new ReportDocument();
        reportdocument.Load(Server.MapPath("Bin/SalesReportbydate.rpt"));
        reportdocument.SetDatabaseLogon("bestlifeuser", "Pass@123");
        reportdocument.SetParameterValue("from", ASPxDateEdit1.Text);
        reportdocument.SetParameterValue("to", ASPxDateEdit2.Text);

        CrystalReportViewer1.ReportSource = reportdocument;
        CrystalReportViewer1.ParameterFieldInfo.Clear();
        Session["button"] = "1";
        return true;
    }

    public Boolean button2()
    {
        ReportDocument reportdocument = new ReportDocument();
        reportdocument.Load(Server.MapPath("Bin/SalesReportbyCashier.rpt"));
        reportdocument.SetDatabaseLogon("bestlifeuser", "Pass@123");
        reportdocument.SetParameterValue("cashier", DropDownList1.SelectedValue);
        CrystalReportViewer1.ReportSource = reportdocument;
        CrystalReportViewer1.ParameterFieldInfo.Clear();
        Session["button"] = "2";
        return true;
    }
    public Boolean button3()
    {
        ReportDocument reportdocument = new ReportDocument();
        reportdocument.Load(Server.MapPath("Bin/SalesReportbyall.rpt"));
        reportdocument.SetDatabaseLogon("bestlifeuser", "Pass@123");
        CrystalReportViewer1.ReportSource = reportdocument;
        CrystalReportViewer1.ParameterFieldInfo.Clear();
        
        return true;
    }
    #endregion

}